#!/usr/bin/python

# randomcolours.py

import wx

from random import randrange
from wx.lib.colourdb import *

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(400, 350))

        self.panel = wx.Panel(self, -1)
        self.colors = getColourList()
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(1500)
        self.col_num = len(self.colors)
        self.Centre()

    def OnTimer(self, event):
        self.panel.SetBackgroundColour(wx.RED)
        position = randrange(0, self.col_num-1, 1)
        self.panel.SetBackgroundColour(self.colors[position])
        self.panel.Refresh()

class MyApp(wx.App):
    def OnInit(self):
        updateColourDB()
        frame = MyFrame(None, -1, 'randomcolours.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

